/*
 * codeTable.java
 *
 * Created on May 10, 2006, 1:38 PM
 *
 * To change this template, choose Tools | Options and locate the template under
 * the Source Creation and Management node. Right-click the template and choose
 * Open. You can then make changes to the template in the Source Editor.
 */

/**
 *
 * @author jtma
 */
import java.util.Vector;
import java.util.StringTokenizer;

public class codeTable {
    
    public class CodeStruct {
        public int code;
        public boolean hasChangquan;
        public boolean hasNanquan;
        public boolean hasTaijiquan;
        public boolean hasStraightsword;
        public boolean hasBroadsword;
        public boolean hasStaff;
        public boolean hasSpear;
        public boolean hasTaijiSword;
        public boolean hasSouthernBroadsword;
        public boolean hasSouthernStaff;
        public String description;
        
        public CodeStruct(int code_in, String events, String description_in)
        {
            code = code_in;
            description = description_in;

            hasChangquan = false;
            hasNanquan = false;
            hasTaijiquan = false;
            hasStraightsword = false;
            hasBroadsword = false;
            hasStaff = false;
            hasSpear = false;
            hasTaijiSword = false;
            hasSouthernBroadsword = false;
            hasSouthernStaff = false;

            // parse 'events' string to set boolean values
            StringTokenizer tokens = new StringTokenizer(events, ",");
            while (tokens.hasMoreTokens()) {
              String e = tokens.nextToken();
              if (e.equals("CHANGQUAN")) {
                hasChangquan = true;
                hasStraightsword = true;
                hasBroadsword = true;
                hasStaff = true;
                hasSpear = true;
              }
              else if (e.equals("NANQUAN")) {
                hasNanquan = true;
                hasSouthernBroadsword = true;
                hasSouthernStaff = true;
              }
              else if (e.equals("TAIJIQUAN")) {
                hasTaijiquan = true;
                hasTaijiSword = true;
              }
              else if (e.equals("STRAIGHTSWORD")) {
                hasStraightsword = true;
              }
              else if (e.equals("BROADSWORD")) {
                hasBroadsword = true;
              }
              else if (e.equals("STAFF")) {
                hasStaff = true;
              }
              else if (e.equals("SPEAR")) {
                hasSpear = true;
              }
              else if (e.equals("SOUTHERN BROADSWORD")) {
                hasSouthernBroadsword = true;
              }
              else if (e.equals("SOUTHERN STAFF")) {
                hasSouthernStaff = true;
              }
              else if (e.equals("TAIJI SWORD")) {
                hasTaijiSword = true;
              }
              else {
                System.err.println("Invalid Code Table initialization string: " + e);
                System.exit(1);
              }
            }
        }
    };
    public static Vector lookupTable = new Vector();
    /** Creates a new instance of codes */
    public codeTable() {
        lookupTable.add(new CodeStruct(00, "CHANGQUAN,NANQUAN,TAIJIQUAN", "null code"));
                
        // BALANCES
        // CQ balances
        lookupTable.add(new CodeStruct(10, "CHANGQUAN", "kick and hold leg"));
        lookupTable.add(new CodeStruct(11, "CHANGQUAN", "hold leg behind head"));
        lookupTable.add(new CodeStruct(12, "CHANGQUAN", "backward balance"));
        lookupTable.add(new CodeStruct(13, "CHANGQUAN", "ShiZi balance"));
        // TJ balances
        lookupTable.add(new CodeStruct(14, "TAIJIQUAN", "low balance with leg forward"));
        lookupTable.add(new CodeStruct(15, "TAIJIQUAN", "fish stance"));
        lookupTable.add(new CodeStruct(16, "TAIJIQUAN", "low stepping with kick forward"));
        lookupTable.add(new CodeStruct(17, "TAIJIQUAN", "side kick balance"));

        // KICKS
        // CQ and NQ
        lookupTable.add(new CodeStruct(20, "CHANGQUAN,NANQUAN", "front sweep"));
        // CQ kicks
        lookupTable.add(new CodeStruct(21, "CHANGQUAN", "back sweep"));
        lookupTable.add(new CodeStruct(22, "CHANGQUAN", "split"));
        // TJ kicks
        lookupTable.add(new CodeStruct(23, "TAIJIQUAN", "parting kick, heel kick"));
        lookupTable.add(new CodeStruct(24, "TAIJIQUAN", "outside kick"));
        lookupTable.add(new CodeStruct(25, "TAIJIQUAN", "slide-down"));
        // NQ kicks
        lookupTable.add(new CodeStruct(26, "NANQUAN", "side nail kick"));

        // JUMPS
        lookupTable.add(new CodeStruct(30, "CHANGQUAN,NANQUAN,TAIJIQUAN", "jump slap kick, tornado, lotus kick"));
        // CQ and TJ
        lookupTable.add(new CodeStruct(31, "CHANGQUAN,TAIJIQUAN", "jump straight kick"));
        // CQ only
        lookupTable.add(new CodeStruct(32, "CHANGQUAN", "ariel"));
        lookupTable.add(new CodeStruct(33, "CHANGQUAN", "butterfly, butterfly twist"));

        // TUMBLES
        // NQ only
        lookupTable.add(new CodeStruct(40, "NANQUAN", "tornado fall"));
        lookupTable.add(new CodeStruct(41, "NANQUAN", "carp skip-up"));
        lookupTable.add(new CodeStruct(42, "NANQUAN", "double side-kick"));

        // STANCES
        // CQ TJ NQ
        lookupTable.add(new CodeStruct(50, "CHANGQUAN,NANQUAN,TAIJIQUAN", "bow stance"));
        // CQ and NQ
        lookupTable.add(new CodeStruct(51, "CHANGQUAN,NANQUAN", "horse stance"));
        // CQ and NQ
        lookupTable.add(new CodeStruct(52, "CHANGQUAN,NANQUAN", "empty stance"));
        // CQ TJ NQ
        lookupTable.add(new CodeStruct(53, "CHANGQUAN,NANQUAN,TAIJIQUAN", "drop stance"));
        // TJ only
        lookupTable.add(new CodeStruct(54, "TAIJIQUAN", "Taiji step"));
        // NQ only
        lookupTable.add(new CodeStruct(55, "NANQUAN", "Butterfly stance"));

        // WEAPONS
        // CQ and TJ
        lookupTable.add(new CodeStruct(60, "STRAIGHTSWORD,TAIJI SWORD", "hook sword, parry sword"));
        // CQ and NQ
        lookupTable.add(new CodeStruct(61, "BROADSWORD,SOUTHERN BROADSWORD", "broadsword wrap"));
        // CQ only
        lookupTable.add(new CodeStruct(62, "SPEAR", "spear, lan-na-zha"));
        lookupTable.add(new CodeStruct(63, "STAFF,SPEAR", "staff and spear, figure-8 and uppercut"));
        // CQ only
        lookupTable.add(new CodeStruct(64, "STRAIGHTSWORD,BROADSWORD,STAFF,SPEAR", "throw and catch"));
        // NQ/Southern Staff
        lookupTable.add(new CodeStruct(65, "SOUTHERN STAFF", "southern staff dinggun"));

        // OTHER
        // CQ only
        lookupTable.add(new CodeStruct(70, "CHANGQUAN", "balance less than 2 seconds"));
        // CQ TJ NQ
        lookupTable.add(new CodeStruct(71, "CHANGQUAN,NANQUAN,TAIJIQUAN", "out of floor boundary"));
        lookupTable.add(new CodeStruct(72, "CHANGQUAN,NANQUAN,TAIJIQUAN", "weapon touch ground, let go, touch self, or deformed"));
        lookupTable.add(new CodeStruct(73, "CHANGQUAN,NANQUAN,TAIJIQUAN", "torso shakes, feet move or jump"));
        lookupTable.add(new CodeStruct(74, "CHANGQUAN,NANQUAN,TAIJIQUAN", "extra support (0.2)"));
        lookupTable.add(new CodeStruct(75, "CHANGQUAN,NANQUAN,TAIJIQUAN", "weapon breaks (0.2)"));
        lookupTable.add(new CodeStruct(76, "CHANGQUAN,NANQUAN,TAIJIQUAN", "fall to ground (0.3)"));
        lookupTable.add(new CodeStruct(77, "CHANGQUAN,NANQUAN,TAIJIQUAN", "weapon drops on ground (0.3)"));
    }
    
    public static CodeStruct LookupCode(int code)
    {
        int i;
        for (i = 0; i < lookupTable.size(); i++) {
            CodeStruct c = (CodeStruct) lookupTable.get(i);
            
            if (c.code == code) {
                return c;
            }
        }
        
        return null;
    }
    
    public static boolean isValid(String event, int code)
    {
      if (LookupCode(code) == null) {
          return false;
      }
      
      if (event.equals("CHANGQUAN")) {
          return LookupCode(code).hasChangquan;
      }
      else if (event.equals("NANQUAN")) {
          return LookupCode(code).hasNanquan;
      }
      else if (event.equals("TAIJIQUAN")) {
          return LookupCode(code).hasTaijiquan;
      }
      else if (event.equals("STRAIGHTSWORD")) {
          return LookupCode(code).hasStraightsword;
      }
      else if (event.equals("BROADSWORD")) {
          return LookupCode(code).hasBroadsword;
      }
      else if (event.equals("STAFF")) {
          return LookupCode(code).hasStaff;
      }
      else if (event.equals("SPEAR")) {
          return LookupCode(code).hasSpear;
      }
      else if (event.equals("SOUTHERN BROADSWORD")) {
          return LookupCode(code).hasSouthernBroadsword;
      }
      else if (event.equals("SOUTHERN STAFF")) {
          return LookupCode(code).hasSouthernStaff;
      }
      else if (event.equals("TAIJI SWORD")) {
          return LookupCode(code).hasTaijiSword;
      }
      else {
          System.err.println("Lookuped bad event for codeTable: " + event);
          System.exit(1);
          return false;
      }
    }
}
